<script setup lang="ts">
// import router from '@/router/index'
import { defineProps, defineEmits } from 'vue'
import { useRouter } from 'vue-router'

const props = defineProps<{
  title?: string
  rightText?: string
  back?: () => void
}>()

const router = useRouter()

const onClickLeft = () => {
  if (props.back) return props.back()
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const emit = defineEmits<{
  (event: 'clickRight'): void
}>()
// const onClickRight = () => {
//     emit('clickRight')
// }
</script>

<template>
  <van-nav-bar
    fixed
    left-arrow
    :title="title"
    :right-text="rightText"
    @click-left="onClickLeft"
    @click-right="emit('clickRight')"
  />
</template>

<style scoped lang="scss">
:deep .van-nav-bar {
  &__arrow {
    font-size: 18px;
    color: var(--cp-text1);
  }
  &__text {
    font-size: 16px;
  }
}
</style>
